package com.ljy.system.marvel_sys.common.config.http;

import org.springframework.context.annotation.Configuration;

/**
 * HttpsConfig:修改内嵌Tomcat，HTTP转HTTPS
 *
 * @author LiJunYi
 * @create 2019/7/18
 * @since 1.0.0
 */
@Configuration
public class HttpsConfig {

/*    @Bean
    public TomcatServletWebServerFactory servletContainer() {
        TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory() {
            @Override
            protected void postProcessContext(Context context) {
                SecurityConstraint constraint = new SecurityConstraint();
                constraint.setUserConstraint("CONFIDENTIAL");
                SecurityCollection collection = new SecurityCollection();
                collection.addPattern("/*");
                constraint.addCollection(collection);
                context.addConstraint(constraint);
            }
        };
        tomcat.addAdditionalTomcatConnectors(httpConnector());
        return tomcat;
    }

    @Bean
    public Connector httpConnector() {
        Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
        connector.setScheme("http");
        //监听http的端口号
        connector.setPort(80);
        connector.setSecure(false);
        //监听到http的端口号后转向到的https的端口号
        connector.setRedirectPort(443);
        //这里的端口写成和配置文件一样的端口就Ok
        return connector;
    }*/
}
